package com.byxy.shop.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.byxy.shop.entity.ShoppingCartItem;

public interface ShoppingCartItemDao {
	
	@Select("select * from tb_newbee_mall_shopping_cart_item where user_id = #{userId} and is_deleted = 0")
	List<ShoppingCartItem> selectByUserId(Integer userId);

	@Select("select count(*) from tb_newbee_mall_shopping_cart_item where is_deleted!=1")
	Integer cartCount();
	
	@Select("select * from tb_newbee_mall_shopping_cart_item where cart_item_id = #{cartItemId} and goods_id = #{goodsId} and is_deleted = 0")
	ShoppingCartItem selectByUserIdAndGoodsId(@Param("goodsId") Integer goodsId,@Param("cartItemId") Integer cartItemId);

	@Insert("insert into tb_newbee_mall_shopping_cart_item(user_id,goods_id,goods_count,is_deleted,create_time,update_time) values(#{userId},#{goodsId},#{goodsCount},#{isDeleted},#{createTime},#{updateTime})")
	Integer save(ShoppingCartItem cartItem);

	@Update("update tb_newbee_mall_shopping_cart_item set goods_count=#{goodsCount},is_deleted=#{isDeleted},update_time=#{updateTime} where cart_item_id=#{cartItemId}")
	int updateCart(ShoppingCartItem sct);

	@Delete("delete from tb_newbee_mall_shopping_cart_item where cart_item_id = #{id}")
	int deleteById(Integer id);

}
